<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='https://cdn.staticfile.org/react/16.4.0/umd/react.development.js'></script>
    <script src='https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js'></script>
    <!-- 生产环境中不建议使用 -->
    <script src='https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js'></script>
    <!-- PropTypes文件 -->
    <script src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
</head>

<body>
    <div id='app'>
    </div>
    <script type='text/babel'>
        class Person extends React.Component{

            /*
                我们可以利用static的特性，将propTypes和defaultProps写到类这里，这样整个代码的结构就清晰了很多            
            */
            static propTypes = {
                name:PropTypes.string.isRequired,
                age:PropTypes.number,
                sex:PropTypes.string,
                speak:PropTypes.func
            }

            static defaultProps = {
                sex:'保密',
                age:100
            }

            render(){
                const {name,age,sex,speak} = this.props
                return (
                    <ul>
                        <li>姓名: {name}</li>
                        <li>性别: {sex}</li>
                        <li>年龄: {age+1}</li>
                    </ul>
                )
            }
        }

        function speak(){
            console.log('啦啦啦啦啦')
        }

        const p1 = {name:'刘康',sex:'女',age:23,speak}
        let app = document.getElementById('app')
        ReactDOM.render(<Person {...p1}/>,app)
    </script>
</body>

</html>